home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
spxcht.arc
/
SENDSPX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-02-01
|
6KB
|
190 lines
#include <stdio.h>
#include <nit.h>
#include "bill.h"
long stats=0;
unsigned int Socket=0x5555;
int ConnectionID;
main(argc,argv)
int argc;
char *argv[];
{
int ccode, ConnectionNumber, TransportTime, i=0;
ECBStructure *ConnectionECB, *SendECB, *PoolECB;
SPXStructure *ConnectionSPX, *SendSPX, *PoolSPX;
char far *farcharpointer;
char *data, *ReadData;
void ReceiveESRHandler();
void SendESRHandler();
printf("What is the Connection Number of the station you are sending to: ");
ConnectionNumber = atoi(gets());
IPXInitialize();
if ((ccode = IPXOpenSocket(&Socket, 0x00)) != 0) {
printf("The socket was not opened ");
exit(-1);
}
/* ****************************************************************** */
while (i++ != 5) {
if ((PoolECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL ) {
printf("Out of memory trying to allocate for the PoolECB\n ");
exit(-1);
}
if ((PoolSPX = (SPXStructure *)myalloc(1, sizeof(SPXStructure))) == NULL ) {
printf("Out of memory trying to allocate for the PoolSPX\n ");
}
data = (char *)myalloc(1, 2);
ReadData = (char *)myalloc(1, 2);
farcharpointer = (char far *)ReceiveESRHandler;
PoolECB->ESRAddress = farcharpointer;
PoolECB->ECBSocket = Socket;
PoolECB->FragmentCount = 2;
farcharpointer = (char far *)PoolSPX;
PoolECB->FragmentDescriptor[0].Address = farcharpointer;
PoolECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
farcharpointer = (char far *)data;
PoolECB->FragmentDescriptor[1].Address = farcharpointer;
PoolECB->FragmentDescriptor[1].Size = 2;
PoolSPX->PacketType = (char)5;
PoolSPX->PacketLength = IntSwap( sizeof(SPXStructure));
SPXListenForSequencedPacket(PoolECB);
}
/* **************************************************************** */
if ((ConnectionECB = (ECBStructure *)myalloc(1,sizeof(ECBStructure))) == NULL) {
printf("Out of memory for allocating ConnectionECB\n");
exit(-1);
}
if ((ConnectionSPX = (SPXStructure *)myalloc(1,sizeof(SPXStructure))) == NULL) {
printf("Out of memory for allocating ConnectionSPX\n");
exit(-1);
}
ConnectionSPX->PacketLength = IntSwap(sizeof(SPXStructure));
ConnectionSPX->PacketType = 5;
ConnectionSPX->Destination.Socket = Socket;
ConnectionECB->ECBSocket = Socket;
ConnectionECB->FragmentCount = 1;
farcharpointer = (char far *)ConnectionSPX;
ConnectionECB->FragmentDescriptor[0].Address = farcharpointer;
ConnectionECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
MapConnectionNumberToAddress((unsigned char)ConnectionNumber,
ConnectionSPX->Destination.Network, ConnectionSPX->Destination.Node);
IPXGetLocalTarget( (unsigned char *)ConnectionSPX->Destination.Network,
(unsigned char *)ConnectionECB->ImmediateAddress, TransportTime);
ccode = SPXEstablishConnection( (char)5, (char)0, (int *)&ConnectionID,
ConnectionECB);
if (ccode) {
printf("Connection was not made\n");
exit(-1);
}
while (ConnectionECB->InUse) {
IPXRelinquishControl();
}
switch (ConnectionECB->CompletionCode) {
case 0x00:
printf("Connection ID is: %x\n",ConnectionID);
break;
case 0xED:
printf("No connection established..was receiver ready?\n");
break;
default:
printf("Error during establish connection \n");
break;
}
/* ***************************************************************** */
if ((SendECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL) {
printf("Out of memory for allocation to SendECB\n");
exit(-1);
}
if ((SendSPX = (SPXStructure *)myalloc(1, sizeof(ECBStructure))) == NULL) {
printf("Out of memory for allocation to SendSPX\n");
exit(-1);
}
data = (char *)myalloc(1, 2);
strcpy(data,"xxxxxxxx");
farcharpointer = (char far *)SendESRHandler;
SendECB->ESRAddress = farcharpointer;
SendECB->ECBSocket = Socket;
SendECB->FragmentCount = 2;
farcharpointer = (char far *)SendSPX;
SendECB->FragmentDescriptor[0].Address = farcharpointer;
SendECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
farcharpointer = (char far *)data;
SendECB->FragmentDescriptor[1].Address = farcharpointer;
SendECB->FragmentDescriptor[1].Size = 2;
SendSPX->PacketType = (char)5;
SendSPX->PacketLength = IntSwap(sizeof(SPXStructure));
MapConnectionNumberToAddress((unsigned char)ConnectionNumber,
SendSPX->Destination.Network, SendSPX->Destination.Node);
IPXGetLocalTarget( (unsigned char *)SendSPX->Destination.Network,
(unsigned char *)SendECB->ImmediateAddress, TransportTime);
SendSPX->Destination.Socket = Socket;
printf("Hit any key to continue \n");
*ReadData = 0xFF;
while (strcmp(*ReadData,(char)0x1B) != 0) {
*ReadData = getch();
if (strcmp(*ReadData,(char)0x1B) != 0)
printf("%c",*ReadData);
if (strcmp(*ReadData,(char)0x0D) == 0)
printf("\n");
farcharpointer = (char far *)ReadData;
SendECB->FragmentDescriptor[1].Address = farcharpointer;
SPXSendSequencedPacket(ConnectionID,SendECB);
while (SendECB->InUse)
IPXRelinquishControl();
switch (SendECB->CompletionCode) {
case 0x00:
break;
case 0xED:
printf("\n\nConnection failed \n");
exit(-1);
break;
case 0xEE:
printf("\n\nConnection terminated from other side\n ");
exit(0);
break;
default:
printf("Error occured while trying to send \n");
exit(-1);
break;
}
}
}
void SendESR(ESR_ECB)
ECBStructure *ESR_ECB;
{
stats++;
}
void ReceiveESR(ESR_ECB)
ECBStructure *ESR_ECB;
{
SPXListenForSequencedPacket(ESR_ECB);
}